package cn.js.sangu.unitStore.utils;

import cn.js.sangu.unitStore.dto.LogOperationDTO;
import cn.js.sangu.unitStore.dto.ValueAndNameDTO;

public class DTOConverter {

    // Convert ValueAndNameDTO to LogOperationDTO
    public static LogOperationDTO convertToLogOperationDTO(ValueAndNameDTO dto) {
        if (dto == null) return null;
        return new LogOperationDTO(dto.getName(),dto.getValue());
    }

    public static ValueAndNameDTO convertToValueAndNameDTO(LogOperationDTO dto) {
        if (dto == null) return null;
        return new ValueAndNameDTO(dto.getNum(),dto.getOperation());
    }

//    // Convert LogOperationDTO to ValueAndNameDTO
//    public static ValueAndNameDTO convertToValueAndNameDTO(LogOperationDTO logOperationDTO) {
//        if (logOperationDTO == null) return null;
//
//        // Assuming the operation string is in the format "name set to value"
//        String[] parts = logOperationDTO.getOperation().split(" set to ");
//        if (parts.length != 2) {
//            throw new IllegalArgumentException("Invalid operation format");
//        }
//
//        ValueAndNameDTO valueAndNameDTO = new ValueAndNameDTO();
//        valueAndNameDTO.setName(parts[0].trim());
//        valueAndNameDTO.setValue(logOperationDTO.getNum());
//
//        return valueAndNameDTO;
//    }
}
